package Pixiv;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

public class Post {
	List<NameValuePair> nvps=new ArrayList<>();
	String Post_key;
	public List<NameValuePair> getNvps() {
		return nvps;
	}
	public void setNvps(String post_key,String UserName,String PassWord) {
		nvps.add(new BasicNameValuePair("pixiv_id", UserName));
        nvps.add(new BasicNameValuePair("password", PassWord));
        nvps.add(new BasicNameValuePair("captcha", ""));
        nvps.add(new BasicNameValuePair("g_recaptcha_response", ""));
        nvps.add(new BasicNameValuePair("post_key",post_key));
        nvps.add(new BasicNameValuePair("source", "pc"));
        nvps.add(new BasicNameValuePair("ref", "wwwtop_accounts_index"));
        nvps.add(new BasicNameValuePair("return_to", "http://www.pixiv.net/"));
	}
	public String getPost_Key() {
		return Post_key;
	}
	public void setPost_key(HttpEntity entity) throws Exception, IOException {
		if (entity != null) {
			InputStream inputStream;
            inputStream = entity.getContent();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            String line = "";
            
            while ((line = bufferedReader.readLine()) != null) {
            	 String pattern = "(?<=pixivAccount.postKey\":\")[^\"]*";
                 Pattern r = Pattern.compile(pattern);
                 Matcher m = r.matcher(line);

                 if (m.find( )) {
                    Post_key=m.group();
                 }else {
     			}
            }
        }
	}
}
